package com.rrd.dw.mr.gzip.kafka;


import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.umeng.UmengCreditScore;
import com.ucredit.babel.common.model.umeng.UmengCreditScoreData;
import com.ucredit.babel.common.model.umeng.UmengCreditScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;



import java.io.IOException;

/**
 * 友盟-小额通用分
 * @author rrz
 */

public class UmengCreditScoreParse   extends ParseBase{

    private Text val = new Text();
    private Text key = new Text();

    /**
     *
     * 友盟-小额通用分
     * @param model
     * @throws IOException
     * @throws InterruptedException
     * @return
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        UmengCreditScoreRecord obj = (UmengCreditScoreRecord)model;
        UmengCreditScoreData scoreData = obj.getData();
        UmengCreditScore score = scoreData.getData();

        StringBuilder sb = getBaseInfo(obj, successful);

        //信息
        sb.append(scoreData.getMessage()).append(CRT001);
        //状态码
        sb.append(scoreData.getCode()).append(CRT001);
        //请求ID
        sb.append(scoreData.getRequestId()).append(CRT001);
        //调用返回状态码
        sb.append(score.getStatus()).append(CRT001);
        //新版小额通分
        sb.append(score.getCreditScore()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n","").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_youmeng_smallscore_inc";
    }

    @Override
    public String getType() {
        return RecordType.UMENG_CREDIT_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "友盟小额通用分";
    }
}
